<?php
function get_message_count($uid){
	if(!($uid>0))return;
	$ret=oj_query("select count(1),state from message where receiver_id=$uid and state!='draft' group by state ");
	$ary=array();
	while($row=mysql_fetch_row($ret)) {
		$ary[$row[1]]=$row[0];
	}
	if(!isset($ary['sent']))$ary['sent']=0;
	return $ary;
}
$_user_message=get_message_count($_user_id);
function drawLanguageSelect(){
	global $language_array,$_user_lang,$site_perfix;
	$cookie_key='"' . $site_perfix . 'language"';
	$cookie_value='this.options[this.selectedIndex].value';
	Draw_Options($language_array,'',$_user_lang," onchange='addSimpleCookie($cookie_key,$cookie_value,7);location.reload();' class='float_topright' ");
}
function drawThemeSelect(){
	global $_user_theme,$site_perfix;
	$cookie_key='"' . $site_perfix . 'theme"';
	$cookie_value='this.options[this.selectedIndex].value';
	$style='float:right;display:inline;margin-right:6px;margin-top:6px;';
	$theme_array=array(
		'default'=>_d('theme_default'),
		'tb_green'=>_d('theme_tb_green'),
		'tb_blue'=>_d('theme_tb_blue'),
		'tb_purple'=>_d('theme_tb_purple'),
		'bar_top'=>_d('theme_bar_top'),
	);
	Draw_Options($theme_array,'',$_user_theme," onchange='addSimpleCookie($cookie_key,$cookie_value,7);location.reload();' class='float_topright' ");
}
function drawUserBox($message){
	global $_user_name,$_user_id,$current_url;
	if(isset($_user_name)) {
		/*
		$message_count=$message['sent']+$message['read'];
		$part_message=array('-'=>'a','href'=>'message.php?action=in',_d('user_message') . "$message_count({$message['sent']})");
		if($message['sent']>0)$part_message=array('-'=>'b',$part_message);
		a_draw_html(array(
			array('-'=>'a','class'=>'user','href'=>"user.php?user_id=$_user_id",str_to_html($_user_name)),
			array('-'=>'br'),
			array('-'=>'div','style'=>'width:50%;float:left;',
				array('-'=>'a','href'=>'modifyuser.php',_d('user_update')),'<br/>',
				array('-'=>'a','href'=>"logout.php?url=$current_url",_d('user_logout'))),
			array('-'=>'div','style'=>'width:50%;float:left;',
				$part_message,'<br/>',
				array('-'=>'a','href'=>'showrequest.php?show=self',_d('user_request')),'<br/>'),
			array('-'=>'div','style'=>'clear:both;','')
		));
		*/
		echo "<a class='user' href='user.php?user_id=$_user_id'>" . htmlspecialchars($_user_name) . "</a><br />";
		echo '<div style="width:50%;float:left;">';
			echo '<a href="modifyuser.php">' . _d('user_update') . '</a><br />';
			echo "<a href='logout.php?url=$current_url'>" . _d('user_logout') . '</a>';
		echo '</div><div style="width:50%;float:left;">';
			if($message['sent']>0)echo '<b>';
			$message_count=$message['sent']+$message['read'];
			echo '<a href="message.php?action=in">' . _d('user_message') . "$message_count({$message['sent']})</a>";
			if($message['sent']>0)echo '</b>';
			echo '<br/>';
			echo '<a href="showrequest.php?show=self">' . _d('user_request') . '</a><br />';
		echo '</div><div style="clear:both;"></div>';
	} else {
		echo '<form action="login.php" method="post" onsubmit=\'return check_login("login_name","login_pwd","login_pwd_ori")\'>';
		echo '<input type="hidden" name="url" value="' . str_to_html($_SERVER['REQUEST_URI']) . '"/>';
		echo '<input name="pwd" id="login_pwd" type="hidden"/>';
		echo '<table class="no_border">';
			echo '<tr>';
				echo '<td>' . _d('user_id') . '</td>';
				echo '<td><input name="name" id="login_name"/></td>';
			echo '</tr><tr>';
				echo '<td>' . _d('user_password') . '</td>';
				echo '<td><input id="login_pwd_ori" type="password"/></td>';
			echo '</tr><tr>';
				echo '<td colspan="2"><input type="checkbox" value="1" name="remember"/>' . _d('user_remember') . '</td>';
			echo '</tr><tr>';
				echo '<td><input type="submit" value="' . _d('user_login') . '"/></td>';
				echo '<td><a href="register.php">' . _d('user_register') . '</a></td>';
			echo '</tr>';
		echo '</table></form>';
		echo '<script src="include/md5.js" type="text/javascript"></script>';
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title><?php if(isset($page_title)) echo $page_title; else echo $site_title; ?></title>
		<script src="<?php echo _d('js_lang'); ?>" type="text/javascript"></script>
		<script src="include/ajax.js" type="text/javascript"></script>
		<link href="style/style.css" rel="stylesheet" type="text/css" />
<?php
if(substr($_user_theme,0,3)=='tb_') {
	if($_user_theme=='default')$_theme_color='green';
	else $_theme_color=substr($_user_theme,3);
	if($_theme_color=='green')$_theme_color=array('cfc','385','efc','bfc');
	else if($_theme_color=='blue')$_theme_color=array('ccf','358','ddf','eef');
	else if($_theme_color=='purple')$_theme_color=array('ece','538','ecf','bcf');
?>
		<style type="text/css">
		<?php
			echo "div.wapper {background-color: #{$_theme_color[0]};}";
			echo ".table_list th{background-color: #{$_theme_color[1]};}";
			echo "table.table_list, div.problem_content{background-color: #{$_theme_color[2]};}";
			echo ".header .table_list td:hover, .row_hover tr:hover{background-color: #{$_theme_color[3]};}";
		?>
		</style>
	</head>
<body>
<div class="header">
<div class="wapper">
	<h1 style="float:left;">Knowledge</h1>
<?php drawLanguageSelect(); drawThemeSelect(); ?>
<div style="clear:both;"></div>
</div>
<table border="1" class="table_list">
	<tr>
		<th width="20%"><?php echo _d('menu_knowledge'); ?></th>
		<th width="20%"><?php echo _d('menu_special'); ?></th>
		<th><?php echo _d('menu_user'); ?></th>
		<th width="20%"><?php echo _d('menu_search'); ?></th>
	</tr>
	<tr>
		<td>
			<a href="./"><?php echo _d('menu_home'); ?></a><br />
			<a href="shownode.php"><?php echo _d('menu_root'); ?></a><br />
			<a href="faq.php"><?php echo _d('menu_faq'); ?></a><br />
		</td>
		<td>
			<?php echo '<a href="showrequest.php?start=' . date('Y-m-d',time()-60*60*24*7) . '">' . _d('menu_request') . '</a><br/>'; ?>
			<a href="search.php"><?php echo _d('menu_recent'); ?></a><br />
			<a href="group.php?action=show"><?php echo _d('menu_group'); ?></a><br />
		</td>
		<td>
			<?php drawUserBox($_user_message); ?>
		</td>
		<td>
			<?php draw_search_box('<br />',0); ?>
		</td>
	</tr>
</table>
</div><?php
} else if($_user_theme=='bar_top') { /////////////////////////////////顶端功能条主题/////////////////////////////////////////
?>
		<link href="style/style_bar.css" rel="stylesheet" type="text/css" />
		<style type="text/css">
			div.wapper {background-color: #ccf;}
			.table_list th{background-color: #358;}
			table.table_list, div.problem_content{background-color: #ddf;}
			.header .table_list td:hover, .row_hover tr:hover{background-color: #eef;}
			.row_selected{background-color:#ecf;}
			.row_hover td{border-left:transparent;border-right:transparent;border-top:transparent;border-bottom:1px dashed #aaf;}
		</style>
		<script type="text/javascript"><!--
			function toggleMenu(m){m.style.overflow=(m.style.overflow.length?"":"visible");}
		--></script>
	</head>
<body>
<div class="header">
<div id="bar_top">
	<div class="bar_menu" onclick="toggleMenu(this);">
		<div class="bar_menu_title">Knowledge</div>
		<div style="clear:left"></div>

<div class="bar_menu_expand" style="width:450px;">
	<div style="float:left;width:49%;">
		<a href="./"><?php echo _d('menu_home'); ?></a><br />
		<a href="shownode.php"><?php echo _d('menu_root'); ?></a><br />
		<a href="faq.php"><?php echo _d('menu_faq'); ?></a><br />
	</div>
	<div style="float:left;width:50%;">
		<?php echo '<a href="showrequest.php?start=' . date('Y-m-d',time()-60*60*24*7) . '">' . _d('menu_request') . '</a><br/>'; ?>
		<a href="search.php"><?php echo _d('menu_recent'); ?></a><br />
		<a href="search.php?type=group"><?php echo _d('menu_recent2'); ?></a><br />
		<a href="group.php?action=show"><?php echo _d('menu_group'); ?></a><br />
	</div>
</div>

	</div>
	<div class="bar_menu" onclick="toggleMenu(this);" <?php if(strlen($_user_name)>8)echo 'style="width:' . (strlen($_user_name)+1) . 'em;"'; ?>>
		<div class="bar_menu_title">
<?php echo (isset($_user_name)?str_to_html($_user_name) . ($_user_message['sent']>0?'<span style="color:red">new!</span>':''):_d('user_login')); ?></div>
		<div style="clear:left"></div>
		<div class="bar_menu_expand" style="width:300px;">
		<?php drawUserBox($_user_message); ?>
		</div>
	</div>
	<?php drawLanguageSelect(); drawThemeSelect(); ?>
	<div class="float_topright">
		<?php draw_search_box('&nbsp;',0); ?>
	</div>
	<div style="clear:both;"></div>
</div>
</div>
<?php } ?>

